package com.logger;

import com.logger.handlers.AHandler;
import com.logger.handlers.HandlerManager;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 存储日志的具体操作，包括handler、level、name
 * Created by chenxunlin01 on 2016/1/16.
 */

public class Option {

    private String name;
    private Level level;
    private String[] handlers;

    /**
     * 存储要处理的操作
     */
    private Map<String, AHandler> handlerMap = new ConcurrentHashMap<>();

    public Map<String, AHandler> getHandlerMap() {
        return handlerMap;
    }

    public Level getLevel() {
        return level;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setLevel(Level level) {
        this.level = level;
    }

    public String[] getHandlers() {
        return handlers;
    }

    public void setHandlers(String[] handlers) {
        this.handlers = handlers;
    }

    public synchronized Map<String, AHandler> buildHandlers() {
        handlerMap.clear();
        if (handlers != null) {
            for (String name : handlers) {
                AHandler handler = HandlerManager.getHandler(name);
                if (handler != null) {
                    handlerMap.put(handler.getName(), handler);
                }
            }
        }
        return handlerMap;
    }
}
